package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysTopTitle;
import com.ruoyi.system.service.ISysTopTitleService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 顶部选项卡Controller
 * 
 * @author kuaidou
 * @date 2021-08-27
 */
@Controller
@RequestMapping("/system/title")
public class SysTopTitleController extends BaseController
{
    private String prefix = "system/title";

    @Autowired
    private ISysTopTitleService sysTopTitleService;

    @RequiresPermissions("system:title:view")
    @GetMapping()
    public String title()
    {
        return prefix + "/title";
    }

    /**
     * 查询顶部选项卡列表
     */
    @RequiresPermissions("system:title:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysTopTitle sysTopTitle)
    {
        startPage();
        List<SysTopTitle> list = sysTopTitleService.selectSysTopTitleList(sysTopTitle);
        return getDataTable(list);
    }

    /**
     * 导出顶部选项卡列表
     */
    @RequiresPermissions("system:title:export")
    @Log(title = "顶部选项卡", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysTopTitle sysTopTitle)
    {
        List<SysTopTitle> list = sysTopTitleService.selectSysTopTitleList(sysTopTitle);
        ExcelUtil<SysTopTitle> util = new ExcelUtil<SysTopTitle>(SysTopTitle.class);
        return util.exportExcel(list, "顶部选项卡数据");
    }

    /**
     * 新增顶部选项卡
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存顶部选项卡
     */
    @RequiresPermissions("system:title:add")
    @Log(title = "顶部选项卡", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysTopTitle sysTopTitle)
    {
        return toAjax(sysTopTitleService.insertSysTopTitle(sysTopTitle));
    }

    /**
     * 修改顶部选项卡
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysTopTitle sysTopTitle = sysTopTitleService.selectSysTopTitleById(id);
        mmap.put("sysTopTitle", sysTopTitle);
        return prefix + "/edit";
    }

    /**
     * 修改保存顶部选项卡
     */
    @RequiresPermissions("system:title:edit")
    @Log(title = "顶部选项卡", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysTopTitle sysTopTitle)
    {
        return toAjax(sysTopTitleService.updateSysTopTitle(sysTopTitle));
    }

    /**
     * 删除顶部选项卡
     */
    @RequiresPermissions("system:title:remove")
    @Log(title = "顶部选项卡", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysTopTitleService.deleteSysTopTitleByIds(ids));
    }

    /**
     * 状态修改
     */
    @Log(title = "顶部选项卡", businessType = BusinessType.UPDATE)
    @RequiresPermissions("system:title:edit")
    @PostMapping("/changeStatus")
    @ResponseBody
    public AjaxResult changeStatus(SysTopTitle title)
    {
        return toAjax(sysTopTitleService.updateSysTopTitle(title));
    }
}
